<?php 
/**
 * @author 	 	 faithsmine@gmail.com
 * @copyright            www
 * @version              1.0
 * @name 		 reg.php
 * @todo 		 用户 register
 * @final 		 2009-12-15
 */
define('IN_YCTOOL', true);
session_cache_limiter("private, must-revalidate");
require_once('config.php');
require_once('config2.php');
require_once(DIR_COMM . 'common.php');
$nobarfooter = 1;
// |< ajax 处理 
$ajaxaction	= isset($_GET['ajaxaction']) ? $_GET['ajaxaction'] : "";
$ajax		= isset($_POST['ajax']) ? $_POST['ajax'] : "";
//不需要登录的处理
if($ajaxaction == 'ajax')
{
    if($ajax == 'existemail')
    { 
	$email = isset($_POST['email']) ? $_POST['email'] : "";
	if($user->getOneUser($email)) { echo 1;};
	exit;
    }
}
// ajax 处理 >|

//GET data
$uid = isset($_POST['uid']) ? $_POST['uid'] : 0;
$action	= isset($_GET['action']) ? $_GET['action'] : "";
$actionPost	= isset($_POST['actionPost']) ? $_POST['actionPost'] : ""; 
$userid = $user->userinfo['userid'];
$roles = $user->userinfo['roles'];

//obHeader
$userid && func::obHeader('/admin/index.php');
$getuid	= isset($_GET['uid']) ? $_GET['uid'] : 0;
if($getuid)
{
    $code = isset($_GET['code']) ? $_GET['code'] : "";
    //reg.php?action=send&uid=1003&code=366edab42e2a155080e4e1bf0fc51a2f
    $encode = func::passkeyEncode($getuid);

    if($code != $encode)
    {
        func::showMsg('您的连接错误，请您获取正确的连接。<br /> <br />');
    }
}

if($action == 'send' && $getuid)//用户开始注册
{
    $rs = $user->getUserInfoById($getuid);
}

if($actionPost=='add')
{
 
    $email	= isset($_POST['email']) ? $_POST['email'] : "";  
    $userpass	= isset($_POST['userpass']) ? $_POST['userpass'] : "";   
    $userpass2	= isset($_POST['userpass2']) ? $_POST['userpass2'] : "";  
    $pwdQuestion = isset($_POST['pwdQuestion']) ? $_POST['pwdQuestion'] : ''; 
    $pwdQuestion2= isset($_POST['pwdQuestion2']) ? $_POST['pwdQuestion2'] : '';
    $pwdAnswer   = isset($_POST['pwdAnswer']) ? $_POST['pwdAnswer'] : '';
    $pwdAnswer2  = isset($_POST['pwdAnswer2']) ? $_POST['pwdAnswer2'] : '';

    $username	 = isset($_POST['username']) ? $_POST['username'] : ""; 
    $sex	= isset($_POST['sex']) ? $_POST['sex'] : 0;
    $province	= isset($_POST['province']) ? $_POST['province'] : "";

    $tel	= isset($_POST['tel']) ? $_POST['tel'] : "";
    $address	= isset($_POST['address']) ? $_POST['address'] : "";

    if(!$userid)
    {
	$spVerifyKey = isset($_POST['spVerifyKey']) ? $_POST['spVerifyKey'] : "";
	(strtolower($spVerifyKey) != strtolower($_SESSION['seccode'])) && func::ShowMsg("请输入正确的验证码！");

	if(!func::isEmail($email))
	{
	    func::alertMsg($language['sns_check_email']);
        }
        $usernamet = trim($username); 
        $usernamet = str_replace(" ", "", $usernamet);

        $usernamet = 1 . trim($username); 
        $usernamet = str_replace(" ", "", $usernamet);
        $pos = strpos($usernamet, '管理员') ;

	if( $pos )
	{
	    func::alertMsg('真实姓名中不能出现“管理员”');
        }

	if($userpass != $userpass2 || !$userpass)
	{
	    func::alertMsg($language['sns_check_password']);
	}

	if($user->getOneUser($email))
	{
	    func::alertMsg($language['sns_check_userexist']);
	}
	else
        {
	    //require_once(DIR_COMM . 'pinyin.func.php');
	    //$enname		= Pinyin($username, 1);
	   // !$enname && $enname = trim($_POST['username']);
	    $rs = $_POST;
	    unset($rs['actionPost']);
	    unset($rs['userpass2']);
	    unset($rs['spVerifyKey']);

	    $rs['roles'] = 0;
	    $rs['neartime'] = NOWTIME;
	    $rs['regtime'] = NOWTIME;
	    $rs['email'] = trim($_POST['email']);
	    $rs['username'] = trim($_POST['username']);
	    $rs['userpass'] = md5($_POST['userpass']);
 
            $userids = $addUserid = $user->addUserRs($rs);
            if ($userids)
            {
                func::obHeader('login.php');
            }
	  /*  $userpath = Func::getFilePath2($addUserid, 'userdata/', 'config');

	    $rsmember['userid'] = $addUserid;
	    $rsmember['modifytime2'] = NOWTIME;
            db::insert(DB_TABLEPRE . 'user_member', $rsmember);*/
 
 
/*	    $posttext = '
<HTML><HEAD>
<TITLE>Mail</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset='.Email_CHARSET.'">
</HEAD>
<BODY bgColor=#FFFFFF topmargin=5 leftmargin=5 style="FONT-SIZE:9pt;">
<div>
<br>
<br>
'.$username.' 您好， 请点击以下注册链接完成注册。谢谢！
<br>
<br>
 <a href="http://'.YCTOOL_HTTPHOST.'/c.php?code='.$findpsw.'&email='.$email.'"
>http://'.YCTOOL_HTTPHOST.'/c.php?code='.$findpsw.'&email='.$email.'</a>
</div>
</BODY></HTML>';
            require_once(DIR_COMM . 'sendmail.php');
            $isOk = SendMail($email, $language['sns_confirmreg'], $posttext);
            $isOk && SendMail($useremail, '确认您要加入', $detailhtml);
            func::alertMsg('确认邮件已被发送至您的电子邮箱 '.$email.', 请查看邮件并激活网络，谢谢！','./');
            /**/

	}
    }
}

require_once(DIR_COMM . 'template.func.php');
require_once tpl('reg'.$action.'.html', $tpldir);
?>
